<div class="layuimini-main">

    <div class="layui-form layuimini-form">
		<input type="hidden" name="id" value="{{.admin_user.Id}}">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" disabled  placeholder="请输入用户名" value="{{.admin_user.UserName}}" class="layui-input layui-disabled">
                <tip>填写管理员账号的名称。</tip>
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label ">重置密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" id="user_password_verify" placeholder="非必填项，填写会重置密码" value="" class="layui-input">
				<tip>非必填项，填写会重置密码</tip>
			</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" {{if eq .admin_user.Status 0}} checked {{end}} value="0" title="正常">
                <input type="radio" name="status" {{if eq .admin_user.Status 1}} checked {{end}} value="1" title="禁用">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" placeholder="请输入邮箱" value="{{.admin_user.Email}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">昵称</label>
            <div class="layui-input-block">
                <input type="text" name="nickname" placeholder="请输昵称" value="{{.admin_user.Nickname}}" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label required">角色</label>
            <div class="layui-input-block">
			{{range $index, $elem := .role_data}}
				 <input class="role_ids" {{if $elem.Ischecked}}checked{{end}} type="checkbox" name="role_id[]" value="{{$elem.Id}}" title="{{$elem.Label}}" >
			{{end}}
                
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
			//获取选中的id
			var ids = $(".role_ids").map(function(){ 
				if($(this).is(':checked')) {
					return this.value
				}
			}).get().join(','); 
			
			if(ids.length <= 0){
				layer.msg("请选择角色");
				return false;
			}
			
			var datas =  data.field
			datas.role_ids = ids;
			//console.log(datas);return false;
			var url = "/admin/adminUser/edit"
            $.post(url,data.field,function(resp){
				//console.log(resp)
				if(resp.code == 0){
					//成功
					layer.msg("修改成功",{end:function(){
						table.reload('currentTableId')
						 // 关闭弹出层
						layer.close(parentIndex);
					}});
					
				}else{
					layer.msg(resp.msg);
				}
		    },"json");


            return false;
        });
		
		//密码，文字过滤
		$("#user_password_verify").keyup(function(){
			var biaoshi_str = $(this).val();
			var replace_str = biaoshi_str.replace(/[^a-zA-Z0-9]/g,'')
			$(this).val(replace_str);
			
		});

    });
</script>